# -*-coding:utf-8-*-

from tests.apis.http import *
from tests.apis.base import BaseAPI


class Apps(BaseAPI):
    def __init__(self, *args, **kwargs):
        super(Apps, self).__init__(*args, **kwargs)

    def create_app(self, *args, **kwargs):
        response = http_post('platform/api/apps', kwargs, self.query)
        return self.assert_response_success_data(response)

    def get_app(self, *args, **kwargs):
        app_id = kwargs['app_id']
        response = http_get('platform/api/apps/%s' % app_id, self.query)
        return self.assert_response_success_data(response)

    def update_app(self, *args, **kwargs):
        app_id = kwargs.pop('app_id')
        response = http_put('platform/api/apps/%s' % app_id, kwargs, self.query)
        return self.assert_response_success_data(response)

    def update_app_aspect(self, *args, **kwargs):
        app_id = kwargs.pop('app_id')
        aspect = kwargs.pop('aspect')
        response = http_put('platform/api/apps/%s/%s' % (app_id, aspect), kwargs, self.query)
        return self.assert_response_success_data(response)

    def delete_app_aspect(self, *args, **kwargs):
        app_id = kwargs.pop('app_id')
        aspect = kwargs.pop('aspect')
        response = http_delete('platform/api/apps/%s/%s' % (app_id, aspect), query=self.query)
        return self.assert_response_success_data(response)

    def delete_app(self, *args, **kwargs):
        app_id = kwargs['app_id']
        response = http_delete('platform/api/apps/%s' % app_id, query=self.query)
        return self.assert_response_success_data(response)

    def get_app_list(self, *args, **kwargs):
        response = http_get('platform/api/apps', self.query)
        return self.assert_response_success_data(response)

    def get_app_count(self, *args, **kwargs):
        response = http_get('platform/api/apps/count', self.query)
        return self.assert_response_success_data(response)
